<?php
/**************************************************************************************************
|
| AudioShare - Audio Sharing Script
| http://www.audiosharescript.com
| webmaster@audiosharescript.com
|
|**************************************************************************************************
|
| By using this software you agree that you have read and acknowledged our End-User License 
| Agreement available at http://www.audiosharescript.com/eula.html and to be bound by it.
|
| Copyright (c) 2010 AudioShareScript.com. All rights reserved.
|**************************************************************************************************/

include("include/config.php");
include("include/functions/import.php");
$thebaseurl = $config['baseurl'];
$searchengineCat="";
if(isset($_POST["searchbar_category"]) && $_POST["searchbar_category"])	{
    $searchengineCat=intval($_POST["searchbar_category"]);
}
if($_REQUEST[submitsearch]!="")
{
	$searchterm = $_REQUEST[searchterm];
	$searchfor = "audios";
	
	$searchdata=$searchterm;
	
	if($_REQUEST[country]!="Choose Country")
		$searchdata .= "_".$_REQUEST[country];
	else
		$searchdata .= "_0";
	//if($_REQUEST["year"]!="0")
		$searchdata .= "_".$_REQUEST["year"];	
	//if($_REQUEST[artist]!="0")
		$searchdata .= "_".$_REQUEST[artist];
	//if($_REQUEST["titles"]!="0")
		$searchdata .= "_".$_REQUEST["titles"];
	
		
	if ($searchterm != "")
	{
		$query="SELECT * FROM search_phrases WHERE type='".mysql_real_escape_string($searchfor)."' AND phrase='".mysql_real_escape_string($searchterm)."'";
		$executequery=$conn->execute($query);	
		
		if(mysql_affected_rows()>=1)
		{
			$SID=$executequery->fields['SID'];
		}
		
		if (is_numeric($SID) && $SID != "")
		{
			$query="UPDATE search_phrases SET searchcount=searchcount+1 WHERE SID='".mysql_real_escape_string($SID)."'";
			$executequery=$conn->execute($query);
		}
		else
		{
			$query="INSERT INTO search_phrases SET type='".mysql_real_escape_string($searchfor)."', phrase='".mysql_real_escape_string($searchterm)."'";
			$executequery=$conn->execute($query);
		}
	}
        if($searchengineCat!="")
            $searchdata .="&cat=".$searchengineCat;
	/*echo $searchdata;
	exit;*/
	header("Location:$thebaseurl/search/audios/a/1/$searchdata");
}
else
{
    $searchcat="";
    if($searchengineCat!="")
            $searchcat ="&cat=".$searchengineCat;
	header("Location:$thebaseurl/search/audios/a/1/$searchcat");exit;
}

?>